package com.view.mediator
{
	import com.ApplicationFacade;
	import com.view.component.OneView;

	import org.puremvc.as3.multicore.patterns.mediator.Mediator;
	import org.puremvc.as3.multicore.interfaces.IMediator;
	import org.puremvc.as3.multicore.interfaces.INotification;

	import flash.events.Event;

	public class OneViewMediator extends Mediator implements IMediator
	{
		public static const NAME:String='OneViewMediator';

		public function OneViewMediator(viewComponent:Object)
		{
			super(NAME, viewComponent);
		}

		protected function get oneView():OneView
		{
			return viewComponent as OneView;
		}

		override public function onRegister():void
		{
			oneView.labelText=NAME + " wrote this.";
		}

		override public function listNotificationInterests():Array
		{
			return [ApplicationFacade.VALIDATE_FORMS, ApplicationFacade.RESET_FORMS];
		}

		override public function handleNotification(note:INotification):void
		{
			switch (note.getName())
			{
				case ApplicationFacade.VALIDATE_FORMS:
					var validationObject:Object=new Object();
					validationObject["valid"]=oneView.formIsValid();
					validationObject["vo"]=oneView.viewsVO;
					validationObject["errors"]=oneView.viewsErrors;
					sendNotification(MainViewValidator.FORM_VALIDATION, validationObject, "OneView");
					validationObject=null;
					break;
				case ApplicationFacade.RESET_FORMS:
					oneView.resetForm();
					break;
			}
		}
	}
}